#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QTcpSocket>
#include <QHostAddress>
#include <QMessageBox>
QT_BEGIN_NAMESPACE
namespace Ui { class Widget; }
QT_END_NAMESPACE

class Widget : public QWidget
{
    Q_OBJECT

public:
    Widget(QWidget *parent = nullptr);
    ~Widget();

private slots:
    void on_closebutton_clicked();

    void on_linkbutton_clicked();

private:
    Ui::Widget *ui;
    QTcpSocket* socket;
};
#endif // WIDGET_H
#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    socket=new QTcpSocket;
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_closebutton_clicked()
{
    this->close();
}

void Widget::on_linkbutton_clicked()
{
    QString serverip=ui->serverip->text();
    QString serverport=ui->serverport_2->text();

    socket->connectToHost(QHostAddress(serverip),serverport.toShort());

    connect(socket,&QTcpSocket::connected,[this]()
    {

       QMessageBox::information(this,"提示","连接成功");

    });

    connect(socket,&QTcpSocket::disconnected,[this]()
    {

       QMessageBox::warning(this,"提示","连接失败");



    });


}